package com.hjy.user.service.impl;

import com.hjy.pojo.User;
import com.hjy.service.UserService;
import com.hjy.user.mapper.UserMapper;
import com.rpc.RpcFactory;
import org.apache.zookeeper.KeeperException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.List;

/**
 * 服务对象只要srping 容器管理即可
 * 现在缺少的是注册过程
 * 也就是调换用自定义框架，将当前的对象和实现类接口的信息，通过RpcFacktory 注册到zookeeper 中
 * spring容器是如何创建的，是构造方法
 */
@Service
public class UserServiceImpl extends UnicastRemoteObject implements UserService {

    @Autowired
    private UserMapper userMapper;

    public UserServiceImpl() throws IOException, InterruptedException, KeeperException {
        super();
        System.out.println("我是构造方法");
        RpcFactory.registerService(UserService.class, this);
        System.out.println("注册服务 UserServiceImpl");
    }

    @Override
    public List<User> getUsersByName(String name) throws RemoteException {
        return userMapper.selectByName(name);
    }
}
